<template>
    <div class="glyglAdd">
<el-form ref="form" :model="form" label-width="80px" :rules="rules">
  <el-form-item label="用户名" prop="username">
    <el-input v-model="form.username"></el-input>
  </el-form-item>
  <el-form-item label="权限">
    <el-checkbox-group v-model="form.privileges">
    <el-checkbox :label="1">系管理</el-checkbox>
    <el-checkbox :label="2">专业管理</el-checkbox>
    <el-checkbox :label="4">班级管理</el-checkbox>
    <el-checkbox :label="8">学生管理</el-checkbox>
    <el-checkbox :label="16">教师管理</el-checkbox>
    <el-checkbox :label="32">课程管理</el-checkbox>
    <el-checkbox :label="64">选课修改</el-checkbox>
    <el-checkbox :label="128">管理员管理</el-checkbox>
  </el-checkbox-group>
  </el-form-item>
  
  <el-form-item label="密码" prop="password">
    <el-input v-model="form.password"></el-input>
  </el-form-item>

   
  <el-form-item>
    <el-button type="primary" @click="onSubmit">立即创建</el-button>
    <el-button @click="handleClose">取消</el-button>
  </el-form-item>
</el-form>
    </div>
</template>

<script>
import {glyglAdd} from "@/api/glygl"
  export default {
    data() {
      return {
        form: {
          username: '',
          id:-1,
          password :"",
          privileges:[]
        },
        rules: {
                username: [
                    { required: true, message: '请输入专业名称', trigger: 'blur' },
                ],
                
            },
            options:[{

            }]
      }
    },
    methods: {
      onSubmit() {
        console.log('submit!');
         this.$refs['form'].validate(flag => {
            if(flag){
              this.form["privilege"]=this.form.privileges.reduce((a,b)=>a+b);
                console.log(this.form);
                glyglAdd(this.form).then(res=>{
                  console.log(res);
                  if(res.code===0){
                    this.$message({
                      message:"添加成功",
                      type:"success",
                      duration:1000
                    })
                    this.$emit("done")
                  }
                  
                })
                
            }
         })
      },
      handleClose(){
        this.$emit("close")
      },
      //获取系列表
      // getList(){
      //   departmentAll().then(res=>{
      //     console.log(res);
      //     if(res.code===0){
      //       this.options=res.data
      //     }
      //   })
      // }
    },
    // mounted(){
    //   this.getList()
    // }

  }
</script>